home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 11 / Cream of the Crop 11-2.iso / extra / helpful.zip / ups < prev    next >
Text File  |  1995-08-21  |  66KB  |  2,069 lines

  1.   The UPS Howto
  2.   Harvey J. Stein, hjstein@math.huji.ac.il, Berger Financial Research,
  3.   Ltd.
  4.   v1.3, 16 April 1995
  5.  
  6.   This document will help you connect an uninterruptable power supply to
  7.   a Linux box... if you're lucky...  Copyright (c) 1994 by Harvey J.
  8.   Stein.  You may use this document as you see fit, as long as it
  9.   remains intact.  In particular, this notice (along with the contribu-
  10.   tions below) must remain untouched.
  11.  
  12.   1.  Introduction
  13.  
  14.  
  15.   This HOWTO covers connecting a UPS to a PC running Linux.  The idea is
  16.   to connect the two in such a way that Linux can shutdown cleanly when
  17.   the power goes out.  To a large extent this document is reduntant,
  18.   because all the basic info is contained in the powerd man page that
  19.   comes with the SysVinit package.  None the less, there seems to
  20.   periodically be alot of discussion on the net regarding connecting
  21.   Linux PCs to UPSs (and the versions of Linux that I installed didn't
  22.   come with a powerd man page).  I figured having a HOWTO would be a
  23.   good idea because:
  24.  
  25.  
  26.   o  A second source of information might help to understand how to
  27.      connect Linux to a UPS, even if it's just the same information
  28.      written differently.
  29.  
  30.   o  The HOWTO can serve as a repository for UPS specific data.
  31.  
  32.   o  The HOWTO contains additional details that aren't in the powerd man
  33.      page.
  34.  
  35.   None the less, this does not replace the powerd man page.  Hopefully,
  36.   after reading both, people will be able to deal with UPSs.
  37.  
  38.  
  39.  
  40.   1.1.  Contributors
  41.  
  42.  
  43.   I am forever indebted to those from whom I've received help,
  44.   suggestions, and UPS specific data.  The list includes, in order of
  45.   appearance in this document:
  46.  
  47.  
  48.   o  Miquel van Smoorenburg (miquels@cistron.nl.mugnet.org)
  49.  
  50.   o  Danny ter Haar (danny@caution.cistron.nl.mugnet.org)
  51.  
  52.   o  Hennus Bergman (hennus@sky.nl.mugnet.org)
  53.  
  54.   o  Tom Webster (webster@kaiwan.com)
  55.  
  56.   o  Marek Michalkiewicz (ind43@sun1000.ci.pwr.wroc.pl)
  57.  
  58.   o  Christian G. Holtje (docwhat@uiuc.edu)
  59.  
  60.   o  Ben Galliart (bgallia@orion.it.luc.edu)
  61.  
  62.   o  Lam Dang (angit@netcom.com)
  63.  
  64.  
  65.  
  66.  
  67.   1.2.  Important disclaimer
  68.  
  69.   I really can't guarantee that any of this will work for you.
  70.   Connecting a UPS to a computer can be a tricky business.  One or the
  71.   other or both might burn out, blow up, catch fire, or start World War
  72.   Three.  Furthermore, I only have direct experience with the Advice
  73.   1200 A UPS, and I didn't have to make a cable.  So, BE CAREFUL.
  74.   GATHER ALL INFORMATION YOU CAN ON YOUR UPS.  THINK FIRST.  DON'T
  75.   IMPLICITLY TRUST ANYTHING YOU READ HERE.
  76.  
  77.   On the other hand, I managed to get everything working with my UPSes,
  78.   without much information from the manufacturer, and without burning
  79.   out anything, so it is possible.
  80.  
  81.  
  82.  
  83.   1.3.  Other documents
  84.  
  85.   This document does not cover the general features and capabilities of
  86.   UPSs.  For this type of information, you might turn to the UPS.faq,
  87.   which is available via anonymous FTP from navigator.jpl.nasa.gov
  88.   (128.149.23.82) in pub/doc/faq/UPS.faq, and can probably be found
  89.   somewhere on rtfm.mit.edu.  It is maintained by Nick Christenson
  90.   (npc@minotaur.jpl.nasa.gov).  In email to him, he'd like that you put
  91.   UPS or UPS FAQ or something along these lines in the Subject line of
  92.   the message.
  93.  
  94.  
  95.  
  96.   2.  What you need to do (summary)
  97.  
  98.  
  99.  
  100.  
  101.   o  Plug the PC into the UPS.
  102.  
  103.   o  Connect the PC's serial port to the UPS with a special cable.
  104.  
  105.   o  Run powerd on the PC.
  106.  
  107.   o  Setup your initd to do something reasonable on powerfail and
  108.      powerok events (like start a shutdown and kill any currently
  109.      running shutdowns, respectively, for example).
  110.  
  111.  
  112.   3.  How it's supposed to work
  113.  
  114.  
  115.  
  116.      UPS's job
  117.         When the power goes out, the UPS continues to power the PC and
  118.         signals that the power went out by throwing a relay or turning
  119.         on an opticoupler on it's control port.
  120.  
  121.  
  122.      Cable's job
  123.         The cable is designed so that when the UPS throws said relay,
  124.         this causes a particular serial port control line (typically
  125.         DCD) to go high.
  126.  
  127.  
  128.      Powerd's job
  129.         Powerd monitors the serial port.  Keeps raised/lowered whatever
  130.         serial port control lines the UPS needs to have raised/lowered
  131.         (typically, DTR must be kept high and whatever line shuts off
  132.         the UPS must be kept low).  When powerd sees the UPS control
  133.         line go high, it writes FAIL to /etc/powerfail and sends the
  134.         initd process a SIGPWR signal.  When the control line goes low
  135.         again, it writes OK to /etc/powerfail and sends initd a SIGPWR
  136.         signal.
  137.  
  138.  
  139.      Initd's job (aside from everything else it does)
  140.         When it receives a SIGPWR, it looks at /etc/powerfail.  If it
  141.         contains FAIL it runs the powerfail entry from /etc/inittab.  If
  142.         it contains OK it runs the powerokwait entry from inittab.
  143.  
  144.  
  145.  
  146.   4.  Where to get the appropriate software
  147.  
  148.   When I last looked, the package to pick up was
  149.   /pub/Linux/system/Daemons/SysVinit-2.50.tgz from sunsite.unc.edu or a
  150.   mirror.  It includes a copy of powerd.c, shutdown.c, an initd that
  151.   understands what to do with SIGPWR and can handle powerfail and
  152.   powerokwait entries in the inittab file.
  153.  
  154.   Of course, by now, I'm sure much newer versions are available.
  155.   Whatever you get might differ from the description here, but will
  156.   probably adhere to the overall philosophy.
  157.  
  158.  
  159.   5.  How to set things up
  160.  
  161.  
  162.   The following presupposes that you have a cable that works properly
  163.   with powerd.c.  If you're not sure that your cable works (or how it
  164.   works), see section ``Reverse-engineering cables and hacking
  165.   powerd.c'' for information on dealing with poorly described cables and
  166.   reconfiguring powerd.c.  Sections ``Serial port pin assignments'' and
  167.   ``Ioctl to RS232 correspondence'' will also be useful.
  168.  
  169.   If you need to make a cable, see section ``How to make a cable'' for
  170.   the overall details, and the subsection of section ``Info on selected
  171.   UPSs'' that refers to your UPS.  The latter might also include
  172.   information on manufacturer supplied cables.  You'll probably want to
  173.   read all of section ``Info on selected UPSs'' because each section has
  174.   afew additional generally helpful details.
  175.  
  176.  
  177.   o  Edit /etc/inittab.  Put in something like this:
  178.  
  179.  
  180.  
  181.      # What to do when power fails (Halt system & drain battery :):
  182.      pf::powerfail:/etc/powerfailscript +5
  183.  
  184.      # If power is back before shutdown, cancel the running shutdown.
  185.      pg:0123456:powerokwait:/etc/powerokscript
  186.  
  187.  
  188.  
  189.  
  190.  
  191.   o  Write scripts /etc/powerfailscript and /etc/powerokscript to
  192.      shutdown in 5 minutes (or whatever's appropriate) and kill any
  193.      existing shutdown, respectively.  Depending on the version of
  194.      shutdown that you're using, this will be either so trivial that
  195.      you'll dispense with the scripts, or be a 1 line bash script,
  196.      something along the lines of:
  197.  
  198.  
  199.          kill `ps -aux | grep "shutdown" | grep -v grep | awk '{print $2}'`
  200.  
  201.  
  202.  
  203.   and you'll keep the scripts.  (In case it doesn't come out right, the
  204.   first single quote on the above line is a backquote, the second and
  205.   third are single quotes, and the last is also a backquote.)
  206.  
  207.   o  Tell initd to re-process the inittab file with the command:
  208.  
  209.  
  210.          telinit q
  211.  
  212.  
  213.  
  214.  
  215.   o  Edit rc.local so that powerd gets run upon startup.  The syntax is:
  216.  
  217.  
  218.          powerd <line>
  219.  
  220.  
  221.  
  222.  
  223.   Replace <line> with the serial port that the modem is connected, such
  224.   as /dev/cua1.
  225.  
  226.   o  Connect PC's serial port to UPS's serial port.  DO NOT PLUG PC INTO
  227.      UPS YET.
  228.  
  229.   o  Plug a light into the UPS.
  230.  
  231.   o  Turn on the UPS and the light.
  232.  
  233.   o  Run powerd.
  234.  
  235.   o  Test the setup:
  236.  
  237.   o  Yank the UPS's plug.
  238.  
  239.   o  Check that the light stays on.
  240.  
  241.   o  Check that /etc/powerfailscript runs.
  242.  
  243.   o  Check that shutdown is running.
  244.  
  245.   o  Plug the UPS back in.
  246.  
  247.   o  Check that the light stays on.
  248.  
  249.   o  Check that /etc/powerokscript runs.
  250.  
  251.   o  Check that /etc/powerfailscript is not running.
  252.  
  253.   o  Check that shutdown is no longer running.
  254.  
  255.   o  Yank the UPS's plug again.  Leave it out and make sure that the PC
  256.      shuts down properly in the proper amount of time.
  257.  
  258.   o  The Dangerous Part.  After everything seems to be proper, powerdown
  259.      the PC and plug it into the UPS.  Run a script that sync's the hard
  260.      disk every second or so.  Simultaneously run a second script that
  261.      keeps doing a find over your entire hard disk.  The first is to
  262.      make this a little safer and the second is to help draw lots of
  263.      power.  Now, pull the plug on the UPS, check again that shutdown is
  264.      running and wait.  Make sure that the PC shuts down cleanly before
  265.      the battery on the UPS gives out.  This is dangerous because if the
  266.      power goes out before the PC shuts down, you can end up with a
  267.      corrupt file system, and maybe even lose all your files.  You'll
  268.      probably want to do a full backup before this test, and set the
  269.      shutdown time extremely short to begin with.
  270.  
  271.   Congratulations!  You now have a Linux PC that's protected by a UPS
  272.   and will shutdown cleanly when the power goes out!
  273.  
  274.  
  275.  
  276.   6.  User Enhancements
  277.  
  278.  
  279.  
  280.   o  Hack powerd.c to monitor the line indicating that the batteries are
  281.      low.  When the batteries get low, do an immediate shutdown.
  282.  
  283.   o  Modify shutdown procedure so that if it's shutting down in a
  284.      powerfail situation, then it turns off the UPS after doing
  285.      everything necessary.
  286.  
  287.  
  288.   7.  How to make a cable
  289.  
  290.   This section is just from messages I've seen on the net.  I haven't
  291.   done it so I can't write from experience.  If anyone has, please write
  292.   this section for me :).  See also the message about the GPS1000
  293.   contained in section ``GPS1000 from ACCODATA''
  294.  
  295.  
  296.  
  297.  
  298.  
  299.  
  300.  
  301.  
  302.  
  303.  
  304.  
  305.  
  306.  
  307.  
  308.  
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.      >From miquels@caution.cistron.nl.mugnet.org Wed Jul 21 14:26:33 1993
  332.      Newsgroups: comp.os.linux
  333.      Subject: Re: UPS interface for Linux?
  334.      From: miquels@caution.cistron.nl.mugnet.org (Miquel van Smoorenburg)
  335.      Date: Sat, 17 Jul 93 18:03:37
  336.      Distribution: world
  337.      Organization: Cistron Electronics.
  338.  
  339.      In article <1993Jul15.184450.5193@excaliber.uucp>
  340.      joel@rac1.wam.umd.edu (Joel M. Hoffman) writes:
  341.      >I'm in the process of buying a UPS (Uninteruptable Power Supply), and
  342.      >notice that some of them have interfaces for LAN's to signal the LAN
  343.      >when the power fails.
  344.      >
  345.      >Is there such an interface for Linux?
  346.      >
  347.      >Thanks.
  348.      >
  349.      >-Joel
  350.      >(joel@wam.umd.edu)
  351.      >
  352.  
  353.      When I worked on the last versioon of SysVinit (Now version 2.4),
  354.      I temporarily had a UPS on my computer, so I added support for it.
  355.      You might have seen that in the latest <signal.h> header files there
  356.      is a #define SIGPWR 30 now :-). Anyway, I did not have such a special
  357.      interface but the output of most UPS's is just a relais that makes or breaks
  358.      on power interrupt. I thought up a simple way to connect this to the
  359.      DCD line of the serial port. In the SysVinit package there is a daemon
  360.      called 'powerd' that keeps an eye on that serial line and sends SIGPWR
  361.      to init when the status changes, so that init can do something (such as
  362.      bringing the system down within 5 minutes). How to connect the UPS to
  363.      the serial line is described in the source "powerd.c", but I will
  364.      draw it here for explanation:
  365.  
  366.                           +------------------------o  DTR
  367.                           |
  368.                         +---+
  369.                         |   | resistor
  370.                         |   | 10 kilo-Ohm
  371.                         |   |
  372.                         +---+                                To serial port.
  373.                           |
  374.             +-----o-------+------------------------o  DCD
  375.             |             |
  376.             o  UPS        |
  377.           \    relais     |
  378.            \              |
  379.             |             |
  380.             +-----o-------+------------------------o  GND
  381.  
  382.      Nice drawing eh?
  383.  
  384.      Hope this helps.
  385.      SysVinit can be found on sunsite (and tsx-11 probably) as
  386.      SysVinit2.4.tar.z
  387.  
  388.      Mike.
  389.  
  390.      --
  391.  
  392.      Miquel van Smoorenburg, <miquels@cistron.nl.mugnet.org>
  393.      Ibmio.com: cannot open CONFIG.SYS: file handle broke off.
  394.  
  395.  
  396.      >From danny@caution.cistron.nl.mugnet.org Wed Jul 21 14:27:04 1993
  397.      Newsgroups: comp.os.linux
  398.      Subject: Re: UPS interface for Linux?
  399.      From: danny@caution.cistron.nl.mugnet.org (Danny ter Haar)
  400.      Date: Mon, 19 Jul 93 11:02:14
  401.      Distribution: world
  402.      Organization: Cistron Electronics.
  403.  
  404.      In article <9307174330@caution.cistron.nl.mugnet.org>
  405.      miquels@caution.cistron.nl.mugnet.org (Miquel van Smoorenburg) writes:
  406.      >How to connect the UPS to the serial line is described in the source
  407.      >"powerd.c", but I will draw it here for explanation:
  408.  
  409.      The drawing wasn't really clear, please use this one in stead !
  410.      >
  411.      >                     +------------------------o  DTR
  412.      >                     |
  413.      >                   +---+
  414.      >                   |   | resistor
  415.      >                   |   | 10 kilo-Ohm
  416.      >                   |   |
  417.      >                   +---+                                To serial port.
  418.      >                     |
  419.      >       +-----o-------+------------------------o  DCD
  420.      >       |
  421.      >       o  UPS
  422.      >     \    relais
  423.      >      \
  424.      >       |
  425.      >       +-----o--------------------------------o  GND
  426.      >
  427.  
  428.      The DTR is kept high, when the UPS's power input is gone it
  429.      will close the relais . The computer is monitoring
  430.      the DCD input port to go LOW . When this happens it will start a
  431.      shutdown sequence...
  432.  
  433.      _____
  434.      Danny
  435.  
  436.      --
  437.      <=====================================================================>
  438.      Danny ter Haar  <dannyth@hacktic.nl> or <danny@cistron.nl.mugnet.org>
  439.      Robins law #103: 'a couple of lightyears can't part good friends'
  440.  
  441.  
  442.  
  443.  
  444.   8.  Reverse-engineering cables and hacking powerd.c
  445.  
  446.   Try to get documentation for the cables that your UPS seller supplies.
  447.   In particular find out:
  448.  
  449.  
  450.   o  What lines need to be kept high.
  451.  
  452.   o  What line(s) turn off the UPS.
  453.  
  454.   o  What lines the UPS toggles to indicate that:
  455.  
  456.   o  Power is out.
  457.  
  458.   o  Battery is low.
  459.  
  460.   You then need to hack powerd.c appropriately.
  461.  
  462.  
  463.   If you have trouble getting the above information, or just want to
  464.   check it (a good idea) the following program  might help.  It's a
  465.   hacked version of powerd.c.  It allows you to set the necessary port
  466.   flags from the command line and then monitors the port, displaying the
  467.   control lines every second.  I used it as "upscheck /dev/cua1 2" (for
  468.   example) to set the 2nd bit (DTR) and to clear the other bits.  The
  469.   number base 2 indicates which bits to set, so for example to set bits
  470.   1, 2 and 3, (and clear the others) use 7.  See the code for details.
  471.  
  472.   Here's the (untested) upscheck.c program.  It's untested because I
  473.   edited the version I originally used to make it clearer, and can't
  474.   test the new version at the moment.
  475.  
  476.  
  477.  
  478.  
  479.  
  480.  
  481.  
  482.  
  483.  
  484.  
  485.  
  486.  
  487.  
  488.  
  489.  
  490.  
  491.  
  492.  
  493.  
  494.  
  495.  
  496.  
  497.  
  498.  
  499.  
  500.  
  501.  
  502.  
  503.  
  504.  
  505.  
  506.  
  507.  
  508.  
  509.  
  510.  
  511.  
  512.  
  513.  
  514.  
  515.  
  516.  
  517.  
  518.  
  519.  
  520.  
  521.  
  522.  
  523.  
  524.  
  525.  
  526.  
  527.  
  528.  
  529.   ______________________________________________________________________
  530.   /*
  531.    * upscheck     Check how UPS & computer communicate.
  532.    *
  533.    * Usage:       upscheck <device> <bits to set>
  534.    *              For example, upscheck /dev/cua4 4 to set bit 3 &
  535.    *              monitor /dev/cua4.
  536.    *
  537.    * Author:      Harvey J. Stein <hjstein@math.huji.ac.il>
  538.    *              (but really just a minor modification of Miquel van
  539.    *              Smoorenburg's <miquels@drinkel.nl.mugnet.org> powerd.c
  540.    *
  541.    * Version:     1.0 19940802
  542.    *
  543.    */
  544.   #include <sys/types.h>
  545.   #include <sys/ioctl.h>
  546.   #include <fcntl.h>
  547.   #include <errno.h>
  548.   #include <stdlib.h>
  549.   #include <unistd.h>
  550.   #include <stdio.h>
  551.   #include <signal.h>
  552.  
  553.   /* Main program. */
  554.   int main(int argc, char **argv)
  555.   {
  556.     int fd;
  557.  
  558.   /*  These TIOCM_* parameters are defined in <linux/termios.h>, which  */
  559.   /*  is indirectly included here.                                      */
  560.     int dtr_bit = TIOCM_DTR;
  561.     int rts_bit = TIOCM_RTS;
  562.     int set_bits;
  563.     int flags;
  564.     int status, oldstat = -1;
  565.     int count = 0;
  566.     int pc;
  567.  
  568.     if (argc < 2) {
  569.           fprintf(stderr, "Usage: upscheck <device> <bits-to-set>\n");
  570.           exit(1);
  571.     }
  572.  
  573.     /* Open monitor device. */
  574.     if ((fd = open(argv[1], O_RDWR | O_NDELAY)) < 0) {
  575.       fprintf(stderr, "upscheck: %s: %s\n", argv[1], sys_errlist[errno]);
  576.       exit(1);}
  577.  
  578.     /* Get the bits to set from the command line. */
  579.     sscanf(argv[2], "%d", &set_bits);
  580.  
  581.     while (1) {
  582.       /* Set the command line specified bits (& only the command line */
  583.       /* specified bits).                                             */
  584.       ioctl(fd, TIOCMSET, &set_bits);
  585.       fprintf(stderr, "Setting %o.\n", set_bits);
  586.  
  587.       sleep(1);
  588.  
  589.       /* Get the current line bits */
  590.       ioctl(fd, TIOCMGET, &flags);
  591.       fprintf(stderr, "Flags are %o.\n", flags);
  592.  
  593.   /*  Fiddle here by changing TIOCM_CTS to some other TIOCM until    */
  594.   /*  this program detects that the power goes out when you yank     */
  595.   /*  the plug on the UPS.  Then you'll know how to modify powerd.c. */
  596.       if (flags & TIOCM_CTS)
  597.         {
  598.           pc = 0 ;
  599.           fprintf(stderr, "power is up.\n");
  600.         }
  601.       else
  602.         {
  603.           pc = pc + 1 ;
  604.           fprintf(stderr, "power is down.\n");
  605.         }
  606.       }
  607.  
  608.     close(fd);
  609.   }
  610.   ______________________________________________________________________
  611.  
  612.  
  613.  
  614.  
  615.  
  616.   9.  Serial port pin assignments
  617.  
  618.   The previous section presupposes knowledge of the correspondence
  619.   between terminal signals and serial port pins.  Here's a reference for
  620.   that correspondence, taken from David Tal's <GSRGAAO@TECHNION.BITNET>
  621.   ``Frequently Used Cables and Connectors'' document.  I'm including a
  622.   diagram illustrating the connectors, and a table listing the
  623.   correspondence between pin numbers and terminal line signals.
  624.  
  625.   |       |        |        |       |         |          |                                |
  626.   |DB-25  |  DB-9  |  Name  |  EIA  |  CCITT  |  DTE-DCE |  Description                   |
  627.   |Pin #  |  Pin # |        |       |         |          |                                |
  628.   +-------+--------+--------+-------+---------+----------+--------------------------------+
  629.   |1      |        |  FG    |  AA   |  101    |  ---     | Frame Ground/Chassis GND       |
  630.   |2      |  3     |  TD    |  BA   |  103    |  --->    | Transmitted Data, TxD          |
  631.   |3      |  2     |  RD    |  BB   |  104    |  <---    |  Received Data, RxD            |
  632.   |4      |  7     |  RTS   |  CA   |  105    |  --->    | Request To Send                |
  633.   |5      |  8     |  CTS   |  CB   |  106    |  <---    |  Clear To Send                 |
  634.   |6      |  6     |  DSR   |  CC   |  107    |  <---    |  Data Set Ready                |
  635.   |7      |  5     |  SG    |  AB   |  102    |  ----    | Signal Ground, GND             |
  636.   |8      |  1     |  DCD   |  CF   |  109    |  <---    |  Data Carrier Detect           |
  637.   |9      |        |  --    |  --   |  -      |  -       | Positive DC test voltage       |
  638.   |10     |        |  --    |  --   |  -      |  -       | Negative DC test voltage       |
  639.   |11     |        |  QM    |  --   |  -      |  <---    |  Equalizer mode                |
  640.   |12     |        |  SDCD  |  SCF  |  122    |  <---    |  Secondary Data Carrier Detect |
  641.   |13     |        |  SCTS  |  SCB  |  121    |  <---    |  Secondary Clear To Send       |
  642.   |14     |        |  STD   |  SBA  |  118    |  --->    | Secondary Transmitted Data     |
  643.   |15     |        |  TC    |  DB   |  114    |  <---    |  Transmitter (signal) Clock    |
  644.   |16     |        |  SRD   |  SBB  |  119    |  <---    |  Secondary Receiver Clock      |
  645.   |17     |        |  RC    |  DD   |  115    |  --->    | Receiver (signal) Clock        |
  646.   |18     |        |  DCR   |  --   |  -      |  <---    |  Divided Clock Receiver        |
  647.   |19     |        |  SRTS  |  SCA  |  120    |  --->    | Secondary Request To Send      |
  648.   |20     |  4     |  DTR   |  CD   |  108.2  |  --->    | Data Terminal Ready            |
  649.   |21     |        |  SQ    |  CG   |  110    |  <---    |  Signal Quality Detect         |
  650.   |22     |  9     |  RI    |  CE   |  125    |  <---    |  Ring Indicator                |
  651.   |23     |        |  --    |  CH   |  111    |  --->    | Data rate selector             |
  652.   |24     |        |  --    |  CI   |  112    |  <---    |  Data rate selector            |
  653.   |25     |        |  TC    |  DA   |  113    |  <---    |  Transmitted Clock             |
  654.  
  655.  
  656.       Pin Assignment for the Serial Port (RS-232C), 25-pin and 9-pin
  657.  
  658.  
  659.  
  660.  
  661.   ______________________________________________________________________
  662.  
  663.           1                         13         1         5
  664.         _______________________________      _______________
  665.         \  . . . . . . . . . . . . .  /      \  . . . . .  /    RS232-connectors
  666.          \  . . . . . . . . . . . .  /        \  . . . .  /     seen from outside
  667.           ---------------------------          -----------      of computer.
  668.           14                      25            6       9
  669.  
  670.      DTE : Data Terminal Equipment (i.e. computer)
  671.      DCE : Data Communications Equipment (i.e. modem)
  672.      RxD : Data received; 1 is transmitted "low", 0 as "high"
  673.      TxD : Data sent; 1 is transmitted "low", 0 as "high"
  674.      DTR : DTE announces that it is powered up and ready to communicate
  675.      DSR : DCE announces that it is ready to communicate; low=modem hangup
  676.      RTS : DTE asks DCE for permission to send data
  677.      CTS : DCE agrees on RTS
  678.      RI  : DCE signals the DTE that an establishment of a connection is attempted
  679.      DCD : DCE announces that a connection is established
  680.   ______________________________________________________________________
  681.  
  682.  
  683.  
  684.  
  685.   10.  Ioctl to RS232 correspondence
  686.  
  687.   Since you also might need to modify powerd.c to raise and lower the
  688.   correct lines, you might also need the numeric values of different
  689.   terminal signals.  The can be found in /usr/include/linux/termios.h,
  690.   but are reproduced here for reference.  Since they could change,
  691.   you're best off confirming these values against said file.
  692.  
  693.  
  694.  
  695.        ______________________________________________________________________
  696.        /* modem lines */
  697.        #define TIOCM_LE        0x001
  698.        #define TIOCM_DTR       0x002
  699.        #define TIOCM_RTS       0x004
  700.        #define TIOCM_ST        0x008
  701.        #define TIOCM_SR        0x010
  702.        #define TIOCM_CTS       0x020
  703.        #define TIOCM_CAR       0x040
  704.        #define TIOCM_RNG       0x080
  705.        #define TIOCM_DSR       0x100
  706.        #define TIOCM_CD        TIOCM_CAR
  707.        #define TIOCM_RI        TIOCM_RNG
  708.        ______________________________________________________________________
  709.  
  710.  
  711.  
  712.  
  713.   Note that the 3rd column is in Hex.
  714.  
  715.  
  716.  
  717.   11.  Info on selected UPSs
  718.  
  719.  
  720.   This section contains UPS specific information.  What I'd like is to
  721.   have the UPS control port information (what each pin does and needs to
  722.   have done), information on the manufacturer supplied cable (what it
  723.   connects where), and a hacked version of powerd.c which works with the
  724.   UPS.  What I currently have is fairly complete descriptions of setting
  725.   up each UPS.  I'd try to distill out the relevant information, but
  726.   since I can't test each UPS, it's hard to decide exactly what's
  727.   relevant.  Furthermore, each UPS seems to have some additional quirks
  728.   that are nicely described by the authors of each section.  So for now
  729.   I'm leaving everything in.  Makes for a hefty Howto.
  730.  
  731.   Please send me your experiences for inclusion here.
  732.  
  733.  
  734.   11.1.  General Experiences.
  735.  
  736.   I've been saving peoples comments, but haven't gotten permission yet
  737.   to include them here.  Here's a general summary of what I've heard
  738.   from people.
  739.  
  740.   APC: Won't release info on their ``smart'' mode without your signature
  741.   on a non-disclosure agreement.  Thus, people are forced to run their
  742.   ``smart'' UPSes in the ``dumb'' mode as outlined above.
  743.  
  744.   Tripp Lite: One person reported that Tripp lite won't release info
  745.   either.
  746.  
  747.   Upsonic: One person reported that Upsonic has discussed technical
  748.   details over the phone, answered questions via fax and are generally
  749.   helpful.
  750.  
  751.  
  752.  
  753.  
  754.   11.2.  Advice 1200 A
  755.  
  756.   UPS from Advice Electronics, Tel Aviv Israel (they stick their own
  757.   name on the things).
  758.  
  759.   UPS Control Port's pin specifications.
  760.  
  761.  
  762.   o  2 - Power Fail.
  763.  
  764.   o  5 - Battery Low.
  765.  
  766.   o  6 - Shut Down UPS.
  767.  
  768.   o  4 - Common ground for pin 2, 5, 6.
  769.  
  770.   They also gave me the following picture which didn't help me, but may
  771.   help you if you want to build a cable yourself:
  772.  
  773.  
  774.  
  775.  
  776.  
  777.  
  778.  
  779.  
  780.  
  781.  
  782.  
  783.  
  784.  
  785.  
  786.  
  787.  
  788.  
  789.  
  790.  
  791.  
  792.  
  793.   ______________________________________________________________________
  794.            2 ----------+
  795.                        |
  796.                        \
  797.                         \|
  798.                          |--------------
  799.                         /|
  800.                       \/      <--- The "\/" here indicates the type of
  801.                       |            this transister.  I forget what
  802.                       |            denotes what, but this one points
  803.                    +-----+         away from the center line.
  804.                   /  /  /
  805.  
  806.  
  807.            5 ----------+
  808.                        |
  809.                        \
  810.                         \|
  811.                          |--------------
  812.                         /|
  813.                       \/
  814.                       |
  815.                       |
  816.                    +-----+
  817.                   /  /  /
  818.  
  819.  
  820.                          +-------------
  821.                          |
  822.                          /
  823.                 10K    |/
  824.            6 --\/\/\/--|
  825.                        |\
  826.                          \/
  827.                          |
  828.                          |
  829.                       +-----+
  830.                      /  /  /
  831.  
  832.  
  833.            4 ----------+
  834.                        |
  835.                        |
  836.                     +-----+
  837.                    /  /  /
  838.  
  839.   ______________________________________________________________________
  840.  
  841.  
  842.  
  843.  
  844.   Cable supplied
  845.  
  846.   They first gave me a cable that was part of a DOS UPS control package
  847.   called RUPS.  I used this for testing.  When I was satisfied, they
  848.   gave me a cable they use for Netware servers connected to UPSs.  It
  849.   functioned identically.  Here are the details:
  850.  
  851.  
  852.   o  DTR - Powers cable (make powerd.c keep it high).
  853.  
  854.   o  CTS - Power out (stays high and goes low when power goes out).
  855.  
  856.   o  DSR - Battery low (stays high.  Goes low when battery does).
  857.  
  858.  
  859.   o  RTS - Turns off UPS (keep it low.  Set it high to turn off UPS).
  860.  
  861.   (The powerd.c that comes with SysVinit set or left RTS high, causing
  862.   the UPS to shut off immediately when powerd was started up!)
  863.  
  864.  
  865.  
  866.   11.3.  GPS1000 from ACCODATA
  867.  
  868.  
  869.  
  870.  
  871.  
  872.  
  873.  
  874.  
  875.  
  876.  
  877.  
  878.  
  879.  
  880.  
  881.  
  882.  
  883.  
  884.  
  885.  
  886.  
  887.  
  888.  
  889.  
  890.  
  891.  
  892.  
  893.  
  894.  
  895.  
  896.  
  897.  
  898.  
  899.  
  900.  
  901.  
  902.  
  903.  
  904.  
  905.  
  906.  
  907.  
  908.  
  909.  
  910.  
  911.  
  912.  
  913.  
  914.  
  915.  
  916.  
  917.  
  918.  
  919.  
  920.  
  921.  
  922.  
  923.  
  924.  
  925.      >From hennus@sky.nl.mugnet.org Thu Mar 10 15:10:22 1994
  926.      Newsgroups: comp.os.linux.help
  927.      Subject: Re: auto-shutdown with UPS
  928.      From: hennus@sky.nl.mugnet.org (Hennus Bergman)
  929.      Date: Tue, 1 Mar 1994 22:17:45 GMT
  930.      Distribution: world
  931.      Organization: The Organization For Removal Of On-Screen Logos
  932.  
  933.      In article <CRAFFERT.94Feb28125452@nostril.lehman.com>,
  934.      Colin Owen Rafferty <craffert@nostril.lehman.com> wrote:
  935.      >I am about to buy an Uninterruptable Power Supply for my machine, and
  936.      >I would like to get one that has the "auto-shutdown" feature.
  937.      >
  938.      I just got one of those real cheap :-)
  939.      It's a GPS1000 by ACCODATA. Anybody know how good the output
  940.      signal of these things is? [Don't have a scope myself :-(]
  941.  
  942.      >I assume that these each have some kind of serial connection that
  943.      >tells the system information about it.
  944.      >
  945.      I took it apart to find out how it worked. There were three optocouplers
  946.      (two output, one input) connected to a 9 pin connector at the back.
  947.      One turns on when the power fails, and goes off again when the power
  948.      returns. While the power is off, you can use the `input' to shut the
  949.      battery off. [It releases the power-relay.] The third one is some kind
  950.      of feedback to tell that it did accepted the `shut-down command'.
  951.      I think the interface for my UPS was designed to be connected to TTL-level
  952.      signals, but with some resistors it could be connected to serial port.
  953.      It's wired in such a way that using a RS-232 port you cannot use both
  954.      output optocouplers; but the shutdown feedback is not necessary anyway,
  955.      just use the important one. ;-)
  956.      [Note that it is possible to blow the transistor part in optocouplers
  957.      with RS-232 levels if you wire it the wrong way round ;-)]
  958.  
  959.      I was hoping I would be able to connect it to my unused game port,
  960.      but that doesn't have an output, does it?
  961.      I'll probably end up getting an extra printer port for this.
  962.  
  963.      Not all UPS' use optocouplers, some use simple relays, which are
  964.      less critical to connect, but of course not as `nice'.
  965.  
  966.      >Has anyone written a package that watches the UPS and does a shutdown
  967.      >(or something) when the power is off?
  968.      SysVinit-2.4 (and probably 2.5 as well) has a `powerd' daemon that
  969.      continually watches a serial port for presence of the CD (Carrier
  970.      Detect) line and signals init when it drops. Init then activates
  971.      shutdown with a time delay. If the power returns within a few minutes
  972.      the shutdown is cancelled. Very Nice.
  973.      The only problem I had with it is that it doesn't actually tell the
  974.      UPS to turn off when the shutdown is complete. It just sits there with
  975.      a root prompt. I'll probably write a small program to shut it down
  976.      >from /etc/brc. RSN.
  977.  
  978.      >    Colin Rafferty, Lehman Brothers <craffert@lehman.com>
  979.  
  980.      Hennus Bergman
  981.  
  982.  
  983.  
  984.  
  985.  
  986.   11.4.  TrippLite BC750LAN (Standby UPS)
  987.  
  988.  
  989.  
  990.  
  991.   From: Tom Webster <webster@kaiwan.com>
  992.   To: hjstein@MATH.HUJI.AC.IL (Harvey J. Stein)
  993.   Subject: Re: Help - Powerd & UPS - Help
  994.   Date: Mon, 8 Aug 1994 12:26:09 -0700 (PDT)
  995.  
  996.   Harvey,
  997.  
  998.   First off, let me say that I enjoyed reading your HOWTO.  It is about
  999.   what I'd hoped my document might grow into.  I wrote my pseudo-HOWTO
  1000.   late on night because I kept seeing the "Can I hook a UPS up to
  1001.   Linux...." message, about once a month on c.o.l.*.  Mine deals
  1002.   specifically with hooking one vendor's model of UPS (Tripplite's
  1003.   BCxxx/LAN series) to a Linux box and making powerd work with it.
  1004.  
  1005.   It is in need of some upkeep, things have been a little hectic.  Now
  1006.   that I have posted it three or four time in response to questions, I'm
  1007.   finally getting some feedback (which catches these errors).  The
  1008.   problems that I know it has so far are:
  1009.  
  1010.   The proper version of SysVinit is 2.4, not 2.04.
  1011.  
  1012.   There is some argument about whether one or more resistors are needed
  1013.   in my cable.  The only place I really see that it might be needed is
  1014.   in the inverter shutoff, to make sure that I don't send too much
  1015.   voltage to the UPS.  For the sensor circuit I don't see why a DTE
  1016.   device can't stand to have its signal looped back to it.  All that I'm
  1017.   doing is connecting a line that is held high to the Carrier Detect
  1018.   line.
  1019.  
  1020.   I should be a little clearer about how the UPS acts when it goes into
  1021.   powerfail mode.  The Tripplites provide both an open and a closed
  1022.   circuit on powerfail, two different pins and a common negative pin.
  1023.   Thus all I have to do is wire a pin that it held high to the carrier
  1024.   detect line and route this through the UPS's open on powerfail
  1025.   circuit, to cause the carrier detect to drop.  I think that this
  1026.   confuses some people who read Miquel van Smoorenburg's description of
  1027.   a UPS that only provides only a closed circuit on powerfail, and
  1028.   requires a much more complex cable.
  1029.  
  1030.   Well that is all I can think of for now.  I'm planning on seeing if my
  1031.   cable will still operate if I insert resistors into all of the
  1032.   circuits.  If it does then I'll make the changes to my document,
  1033.   should find out this weekend.
  1034.  
  1035.  
  1036.   Tom
  1037.  
  1038.   ----------------
  1039.  
  1040.   Of Linux and Uninterruptible Power Supplies
  1041.   [or How to connect a TrippLite BCXXXLAN UPS]
  1042.  
  1043.   by Tom Webster <webster@kaiwan.com>
  1044.      05/20/94 (Version 1.0)
  1045.  
  1046.   1.0 Introduction
  1047.   I struggled through connecting a TrippLite BC750LAN (Standby UPS) to
  1048.   my Linux box about six months ago.  Since then I've seen several
  1049.   requests for information on this subject, so I'm putting it in a
  1050.   relatively stable format so I can just send this out when the question
  1051.   reappears.
  1052.  
  1053.   1.1 The Results
  1054.   When the power fails in my apartment, several things happen:
  1055.  
  1056.      1.  The UPS switches its inverter on and the computer starts
  1057.          drawing off of the UPS.  The warning beeper also starts going
  1058.          off.  If the power comes back on, the UPS shuts the inverter
  1059.          down and switches back to line power.  Nothing else happens,
  1060.          other than the beeper turns off.
  1061.  
  1062.      2.  If the power is off for ~15-30 seconds, the system will send
  1063.          a message to the users (via wall) and initiate a shutdown
  1064.          (to halt) in five minutes.  If the power comes back on, the
  1065.          shutdown is canceled and a message stating this is sent
  1066.          to the users (via wall) stating that the shutdown has been
  1067.          canceled.
  1068.  
  1069.      3.  While the system is shutting itself down, its dying act is to
  1070.          shut off the inverter on the UPS, killing power to the system.
  1071.          This is done after the disks are unmounted, and is done to
  1072.          prevent the halted system from draining power from the UPS.
  1073.  
  1074.      4.  When the line power comes back on, the system restarts normally.
  1075.  
  1076.   The BC750 has enough juice to keep my system going for quite some
  1077.   time, so why do I only run it off of the UPS for five minutes?  The
  1078.   answer rests in a couple of 'rules-of-thumb' (your mileage may vary):
  1079.  
  1080.      a.  If the power browns out or blacks out, 90% of the time it will
  1081.          be out for 0-2 minutes.
  1082.  
  1083.      b.  If it is out for longer, it will be out for .5-3+ hours.
  1084.  
  1085.      c.  If it is out for a while (see b), the power will yo-yo at least
  1086.          once while the power company is working on it.  (The power
  1087.          will come up for 5-45 seconds, and then fail again.)
  1088.  
  1089.   So, I set my system up to cover the majority of the power outages I
  1090.   get, without trying to cover the really long ones.  I also keep plenty
  1091.   of reserve in the UPS to handle yo-yo situations.
  1092.  
  1093.   1.2  Disclaimer
  1094.   I make no warranties or guarantees as to the suitability or sanity of
  1095.   following my advice.  This is how my system is setup, and as far as I
  1096.   can tell it works fine for me.  Your setup may need to be different to
  1097.   fit your needs, especially if you are using different UPS hardware.
  1098.  
  1099.   2.0  Hardware
  1100.   In the case of my UPS, I thought that the RS-232 interface was
  1101.   something of a misnomer.  I was expecting the UPS to send and receive
  1102.   data, like talking to your modem with Hayes "AT" commands.  This was
  1103.   not the case.  It seems that it is called an RS-232 interface because
  1104.   it stays within the voltage and signal limits of the RS-232 spec.  To
  1105.   communicate with the UPS, you need to be able to sense changes in
  1106.   state on certain lines and change the state of other lines.  The fact
  1107.   that these lines may have nothing in common to the lines your system
  1108.   might expect to use, if it were talking to say a modem or printer, is
  1109.   probably why the UPS needs special cables to allow software (including
  1110.   the manufacturer's) to communicate with the UPS.
  1111.  
  1112.   Through trial and error with a RS-232 patch panel, I was able to come
  1113.   up with this cable diagram for the cable between the UPS and the
  1114.   computer.  Please note that I did this without looking at the official
  1115.   TrippLite cable and it may be different.
  1116.  
  1117.             UPS                System
  1118.            DB-25               DB-25
  1119.              1 <-------------->  1       Ground
  1120.  
  1121.              2 <-------------->  4       Power Fail
  1122.              8 <-------------->  8       Sensing Circuit
  1123.              3 <-------------->  2       Inverter Shutdown
  1124.             20 <--------------> 22       Circuit
  1125.  
  1126.   Once you have the cable patched together, just hook the UPS side to
  1127.   the UPS and the System side to a free serial port on your Linux box.
  1128.   You will probably have to mess around with 9->25 and 25->9 adapters
  1129.   to get your cable to fit, but you and a good computer store should
  1130.   be able to handle this.
  1131.  
  1132.   3.0 Software
  1133.   The software that I use is all available to Linux users and comes
  1134.   with most distributions (SLS and Slackware at least).  This setup
  1135.   has worked for me through Kernels .99.9, .99.14, and 1.00.
  1136.  
  1137.   3.1 System V Init
  1138.   This package is needed to make the whole thing work.  If you are
  1139.   still using the "Simple Init" package, perhaps it is time you looked
  1140.   at upgrading.  The version I am using is 2.04, and I believe that
  1141.   Miquel van Smoorenburg is the author of the package.
  1142.  
  1143.   3.2 powerd
  1144.   powerd is the power daemon, by default is sits and watches for a
  1145.   change in state on the DCD line and reports these changes to the
  1146.   system via the signal mechanism.  The source for powerd is provided
  1147.   in the System V Init package.  Compile it, move it to a binary
  1148.   directory (I put it in /sbin on my system), and alter your rc.local
  1149.   script to start the daemon.  The relevant part of my rc.local looks
  1150.   like this:
  1151.  
  1152.       ----- snip -----
  1153.       # Add support for the UPS
  1154.       echo "Starting powerd daemon..."
  1155.       if [ -x /sbin/powerd ]; then
  1156.          /sbin/powerd /dev/cua4
  1157.       fi
  1158.       ----- snip -----
  1159.  
  1160.   3.3 inittab
  1161.   Your inittab needs to be modified to properly handle the signals
  1162.   that powerd will send if there is a power failure.  The relevant
  1163.   lines of my inittab look like this:
  1164.  
  1165.      ----- snip -----
  1166.      # What to do when power fails (shutdown to single user).
  1167.      pf::powerfail:/sbin/shutdown -f +5 "THE POWER IS FAILING"
  1168.  
  1169.      # If power is back before shutdown, cancel the running shutdown.
  1170.      pg:0123456:powerokwait:/sbin/shutdown -c "THE POWER IS BACK"
  1171.  
  1172.      # If power comes back in single user mode, return to multi user mode.
  1173.      ps:S:powerokwait:/sbin/init 2
  1174.      ----- snip -----
  1175.  
  1176.   3.4 rc.0 (brc)
  1177.   Depending on how your system is setup either rc.0 or the brc script
  1178.   is executed immediately prior to shutdown.  These scripts take care
  1179.   of things like unmounting disks and any other last minute clean-up.
  1180.  
  1181.   The inverter shutdown circuit, is designed to signal an inverter
  1182.   shutdown when data is sent out over the DTR line.  In my case,
  1183.   I just cat a short file to the serial port (/etc/passwd - since I
  1184.   know it will always be there).  My rc.0 is as follows, please note
  1185.   that it is overly conservative, the sync can be removed and the
  1186.   sleep times can probably be tightened, but it works so I haven't
  1187.   messed with it.
  1188.  
  1189.     ----- snip -----
  1190.     #! /bin/sh
  1191.     #
  1192.     # brc       This file is executed by init(8) when the system is being
  1193.     #           shutdown (i.e. set to run at level 0).  It usually takes
  1194.     #           care of un-mounting all unneeded file systems.
  1195.     #
  1196.     # Version:  @(#)/etc/brc            2.01    02/17/93
  1197.     #
  1198.     # Authors:  Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>
  1199.     #           Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
  1200.     #
  1201.     # Modified: 01/15/94 - Inverter shutdown support added.
  1202.     #           Tom Webster <webster@kaiwan.com>
  1203.  
  1204.     PATH=/sbin:/bin:/usr/sbin:/usr/bin
  1205.     echo Unmounting file systems.....
  1206.     sync
  1207.     umount -a
  1208.     sleep 2
  1209.     cat /etc/passwd > /dev/cua4
  1210.     sleep 5
  1211.     echo Done.
  1212.     ----- snip -----
  1213.  
  1214.   (On my UPS the inverter is only running when the line power is off,
  1215.   so there is no harm in sending the shutdown signal at every shutdown.)
  1216.  
  1217.   4.0 Conclusion
  1218.   Well that's how I hooked my TrippLite UPS up to my Linux box.
  1219.   Feel free to drop me a line with the results of you attempts,
  1220.   especially if you have any improvements.  :->
  1221.  
  1222.   From: Tom Webster <webster@kaiwan.com>
  1223.   To: hjstein@MATH.HUJI.AC.IL (Harvey J. Stein)
  1224.   Subject: Re: Help - Powerd & UPS - Help
  1225.   Date: Thu, 11 Aug 1994 12:20:50 -0700 (PDT)
  1226.  
  1227.   Harvey,
  1228.  
  1229.   > Like I tried to say, powerd can just run shutdown directly in the
  1230.   > event of a low battery, so that init doesn't need to deal with it &
  1231.   > doesn't need to be hacked - no new signal necessary.  Although this
  1232.   > violates the nice separation of labor between powerd & init, it's
  1233.   > easier than adding another signal.  Or do you just mean another
  1234.   > command?  Something like having powerok/powerfail/powerfailnow as
  1235.   > commands in inittab which execute when SIGPWR is received &
  1236.   > /etc/powerfail contains OK/FAIL/LOWBATT (respectively).  This would be
  1237.   > cleanest, but having powerd execute shutdown -r now is trivial to do
  1238.   > now, and might as well be done - the logic will be the same regardless
  1239.   > of the action that powerd takes when it senses a low battery.  For now
  1240.   > it can just run shutdown, & when init gets hacked it can write LOWBATT
  1241.   > to /etc/powerfail (or whatever the hell the file is called) & give
  1242.   > init a SIGPWR.
  1243.  
  1244.   I'd like to add the LOWBATT command, it would be the cleaner way to do
  1245.   it.  I just need to take a look at the code and see how hard it would
  1246.   be to add it.  Also need to look at my wiring, guess this may mean I've
  1247.   got to run the system all the way down for a final test (once I think I
  1248.   have it working.
  1249.  
  1250.   Tom
  1251.  
  1252.  
  1253.  
  1254.   From: Tom Webster <webster@kaiwan.com>
  1255.   To: hjstein@MATH.HUJI.AC.IL (Harvey J. Stein)
  1256.   Subject: Re: Help - Powerd & UPS - Help
  1257.   Date: Mon, 15 Aug 1994 09:46:06 -0700 (PDT)
  1258.  
  1259.   Harvey,
  1260.  
  1261.   Well, I messed about all weekend taking readings with my multi-
  1262.   tester and comparing it to the scant documentation that I have for
  1263.   the UPS.  The only conclusions I came to were:
  1264.  
  1265.   1.  My system has been working for about 8-9 months now.  If I was
  1266.   going to fry anything, it should have happened by now.
  1267.  
  1268.   2.  If my success is based on my serial hardware doing odd things
  1269.   (I'm using an STB 4COM board), there is no way I'm going to be
  1270.   able to find out on my system.  I'll have to leave that to other
  1271.   poor souls on the net.
  1272.  
  1273.   3.  As far as I can tell the only reason the 10kohm resistor was
  1274.   in Miquel's diagram, was to keep the line higher than DCD, even
  1275.   after the circuit had been shunted to ground.
  1276.  
  1277.   4.  The only circuit that is expected to do anything other that be
  1278.   switched by the UPS (the inverter shutdown circuit) has a 40kohm
  1279.   resistor built into it (inside the UPS).  That should take care of
  1280.   any worries there.
  1281.  
  1282.   5.  Miquel's circuit will work for power fail sensing, and might
  1283.   be extrapolated to include the low battery circuit.  If my circuit
  1284.   proves unviable for others, it would just require more soldering
  1285.   than I'd care to deal with in a cable.
  1286.  
  1287.   In other related news, I broke down this morning and ordered a
  1288.   cable from Tripplite.  I ordered the LanTastic/LAN Manager/Win NT
  1289.   cable, it's just a cable (9M-9F, no software).  This will set me
  1290.   back about $40 (the PC UNIX cable (w/ software) is about $140).
  1291.   The motivation for doing this was three part.
  1292.  
  1293.   (1)  Within a year I'll probably be running Win 4.0, or WinNT 3.5
  1294.   (I beta'ed 3.1) and both should support UPS monitoring (I know NT
  1295.   does and saw the power management icon on a Win4.0 desktop in one
  1296.   of the computer mags).
  1297.  
  1298.   (2)  My current cable isn't going to be compatible with any other
  1299.   monitoring software for other OS's (except by random chance),
  1300.   working to a known (and presumably soon to be common?) cable via a
  1301.   hacked powerd, should widen the audience.
  1302.  
  1303.   (3)  I can always reverse engineer the cable to see if Tripplite
  1304.   is indeed building any safety into their cables.
  1305.  
  1306.   It should be here in a week or so.  In the mean time, I'll start
  1307.   looking into hacking powerd for LOWBATT.
  1308.  
  1309.  
  1310.   Tom
  1311.  
  1312.  
  1313.  
  1314.  
  1315.  
  1316.  
  1317.   11.5.  APC Backup-UPS
  1318.  
  1319.   There seems to be some controversy as to the accuracy of the
  1320.   information here on APC Back-UPSes.  So, please be careful.  I'm
  1321.   prefacing this section with one message of caution I received.  It
  1322.   might not make alot of sense before the rest of this section is read,
  1323.   but this way, at least you're more likely to see it.  And again, since
  1324.   I don't have any APC UPS units, I can't verify the accruacy of either
  1325.   of these messages.
  1326.  
  1327.  
  1328.   11.5.1.  A message of caution
  1329.  
  1330.  
  1331.  
  1332.        From ind43@sun1000.ci.pwr.wroc.pl Sun Oct  9 11:00:42 1994
  1333.        Newsgroups: comp.os.linux.admin
  1334.        Subject: BUPS-HOWTO warning
  1335.        From: ind43@sun1000.ci.pwr.wroc.pl (Marek Michalkiewicz)
  1336.        Date: 6 Oct 1994 18:38:15 GMT
  1337.        Organization: Technical Univeristy of Wroclaw
  1338.        NNTP-Posting-Host: ci3ux.ci.pwr.wroc.pl
  1339.        X-Newsreader: TIN [version 1.2 PL2]
  1340.  
  1341.        If you want to connect the APC Back-UPS to your Linux box, this might
  1342.        be of interest to you.
  1343.  
  1344.        There is a good BUPS-HOWTO which describes how to do this. But it has
  1345.        one "bug".
  1346.  
  1347.        The RTS serial port signal is used to shut down the UPS. The UPS will
  1348.        shut down only if it operates from its battery. The manual says that
  1349.        the shutdown signal must be high for at least 0.5s. But few milliseconds
  1350.        is enough, at least for my APC Back-UPS 600.
  1351.  
  1352.        Using RTS to shut down the UPS can be dangerous, because the RTS goes
  1353.        high when the serial device is opened. The backupsd program then turns
  1354.        RTS off, but it is on (high) for a moment. This kills the power when
  1355.        backupsd is first started and there is a power failure at this time.
  1356.        This can happen for example when the UPS is shut down, unattended,
  1357.        and the power comes back for a while.
  1358.  
  1359.        Either start backupsd before mounting any filesystems for read-write,
  1360.        or (better) use TX (pin 3) instead of RTS (pin 7) to shut down the
  1361.        UPS (pin numbers are for 9-pin plug). Use ioctl(fd, TCSBRKP, 10);
  1362.        to make TX high for one second, for example. Using TX should be safe.
  1363.        Maybe I will post the diffs if time permits...
  1364.  
  1365.        -- Marek Michalkiewicz
  1366.        ind43@ci3ux.ci.pwr.wroc.pl
  1367.  
  1368.  
  1369.  
  1370.  
  1371.  
  1372.  
  1373.   11.5.2.  BUPS-HOWTO
  1374.  
  1375.   Luminated Software Group Presents
  1376.  
  1377.   HOWTO use Back-UPS (by APC) (to keep your linux box from frying)
  1378.  
  1379.  
  1380.   Version: 1.01  BETA
  1381.  
  1382.  
  1383.  
  1384.   Document by: Christian G. Holtje <docwhat@uiuc.edu> Cabling info and
  1385.   help: Ben Galliart <bgallia@orion.it.luc.edu>
  1386.  
  1387.   This document, under one condition, is placed in Public Domain. The
  1388.   one condition is that credit is given where credit is due.  Modify
  1389.   this as much as you want, just give some credit to us who worked.
  1390.  
  1391.   *******************************************************************************
  1392.   Warning!  I, nor any of us who have written or helped with this
  1393.   document, make and guarantees or claims for this text/source/hints.
  1394.   If anything is damaged, we take NO RESPONSIBILITY!  This works to the
  1395.   BEST OF OUR KNOWLEDGE, but we may have made mistakes.  So be careful!
  1396.   *******************************************************************************
  1397.  
  1398.   Al right, you just bought (or are going to buy) a Back-UPS from APC.
  1399.   (Other brands might be able to use this info, with little or no
  1400.   modification, but we don't know)  You've looked at the price of the
  1401.   Power-Chute software/cabling, and just are not sure it's worth the
  1402.   price.  Well, I made my own cable, and my own software and am using it
  1403.   to automatically shut off the power to my linux box when a power
  1404.   failure hits.  Guess what?  You can too!
  1405.  
  1406.   *** The Cable ***
  1407.  
  1408.  
  1409.   This was the hardest part to figure out (I know little about hardware,
  1410.   so Ben did the most work for this).  To build one, you need to buy
  1411.   from your local radio shack (or other part supplier) this stuff:
  1412.  
  1413.  
  1414.  
  1415.        1 9-Position Male D-Subminature Connector (solder-type)
  1416.                [Radio Shack cat. no. 276-1537c]
  1417.        1 9-Position Female D-Subminature Connector (solder-type)
  1418.                [Radio Shack cat. no. 276-1538c]
  1419.        2 casings for the above plugs (usually sold separately)
  1420.        Some stranded wire (wire made of strands, not solid wire)
  1421.  
  1422.  
  1423.  
  1424.  
  1425.   You also need, but may be able to borrow:
  1426.  
  1427.  
  1428.        1 soldering iron
  1429.        solder
  1430.  
  1431.  
  1432.  
  1433.  
  1434.   Okay...this is how you connect it up!
  1435.  
  1436.   These diagrams are looking into the REVERSE SIDE (the side where you
  1437.   solder the wire onto the plugs)  The letters G, R, and B represent the
  1438.   colors of the wires I used, and help to distinguish one line from the
  1439.   next.  (NOTE:  I'm use standard rs-232 (as near as we can tell)
  1440.   numbering.  The APC book uses different numbers.  Ignore them!  Use
  1441.   ours...I already changed the numbers for you!)
  1442.  
  1443.  
  1444.  
  1445.  
  1446.  
  1447.  
  1448.  
  1449.  
  1450.  
  1451.  
  1452.  
  1453.      ---------------------     Male Side! (This goes into the UPS)
  1454.       \  B   R  *  *  * /
  1455.         \  *  *  *  G  /
  1456.           ------------
  1457.  
  1458.  
  1459.      ---------------------     Female Side! (This goes into your COM port)
  1460.       \  R   *  *  *  G /
  1461.         \  *  B  *  *  /
  1462.           ------------
  1463.  
  1464.  
  1465.  
  1466.  
  1467.   For those who like the numbers better:
  1468.  
  1469.  
  1470.  
  1471.                Male            Female
  1472.        ---------------------------------------
  1473.                1               7               Black
  1474.                2               1               Red
  1475.                9               5               Green
  1476.  
  1477.  
  1478.  
  1479.  
  1480.  
  1481.   ---------Aside:  What the rs-232 pins are for!----------- Since we had
  1482.   to dig this info up anyway:
  1483.  
  1484.   >From the REAR (the soldering side) the pins are numbered so:
  1485.  
  1486.  
  1487.  
  1488.           ---------------------
  1489.            \  1   2  3  4  5 /
  1490.              \  6  7  8  9  /
  1491.                ------------
  1492.  
  1493.  
  1494.  
  1495.  
  1496.   The pins mean:
  1497.  
  1498.  
  1499.  
  1500.                Number  Name                    Abbr. (Sometimes written with D prefix)
  1501.                1       Carrier Detect          CD
  1502.                2       Receive Data            RD
  1503.                3       Transmit Data           TD(?)
  1504.                4       Data Terminal Ready     DTR
  1505.                5       Signal Ground           Gnd
  1506.                6       Data Set Ready          DSR
  1507.                7       Request to Send         RTS(?)
  1508.                8       Clear to Send           CS
  1509.                9       Ring Indicator          RI
  1510.  
  1511.  
  1512.  
  1513.  
  1514.   What we did is connect the UPS's RS-232 Line Fail Output to the CD,
  1515.   the UPS's chassis to Gnd, and the UPS's RS-232 Shut Down Input to RTS.
  1516.   Easy now that we told you, no?
  1517.  
  1518.  
  1519.   I have no idea if the software below will work, if you purchase the
  1520.   cable from APC.  It might, and it might not.
  1521.  
  1522.  
  1523.   *** The Software ***
  1524.  
  1525.   Okay, I use the SysVInit package by Miquel van Smoorenburg for Linux.
  1526.   (see end for file locations, credits, email addresses, etc.)  I don't
  1527.   know what would have to be changed to use someone elses init, but I
  1528.   know this code (following) will work with Miquel's stuff.  Just so I
  1529.   give credit where credit's due.  I looked at Miquel's code to figure
  1530.   out how ioctl()'s worked.  If I didn't have that example, I'd have
  1531.   been in trouble.  I also used the powerfail() routine (verbatim, I
  1532.   think), since it must interact with his init, I thought that he should
  1533.   know best.  The .c file is at the end of this document, and just needs
  1534.   to be clipped off.  To clip the file, edit away and extra '.sigs' and
  1535.   junk.  This document should end on the line /* End of File */.....cut
  1536.   the rest.
  1537.  
  1538.   This program can either be run as a daemon to check the status of the
  1539.   UPS and report it to init, or it can be run to send the kill-power
  1540.   command to the UPS.  The power will only be killed if there is a power
  1541.   problem, and the UPS is running off the battery.  Once the power is
  1542.   restored, it turns back on.
  1543.  
  1544.   To run as a daemon, just type: backupsd /dev/backups
  1545.  
  1546.   /dev/backups is a link to /dev/cua0 at the moment (COM 1, for you
  1547.   DOSers).  The niceness of the link is that I can just re-link the
  1548.   device if I change to com 2 or 3.
  1549.  
  1550.   Then, if the power dies init will run the commands for the powerwait.
  1551.   An example (This is from my /etc/inittab):
  1552.  
  1553.  
  1554.  
  1555.        #Here are the actions for powerfailure.
  1556.        pf::powerwait:/etc/rc.d/rc.power start
  1557.        po::powerokwait:/etc/rc.d/rc.power stop
  1558.  
  1559.  
  1560.  
  1561.  
  1562.   The powerwait will run, if the power goes down, and powerokwait will
  1563.   run if the power comes back up.
  1564.  
  1565.  
  1566.   Here is my entire rc.power:
  1567.  
  1568.  
  1569.  
  1570.  
  1571.  
  1572.  
  1573.  
  1574.  
  1575.  
  1576.  
  1577.  
  1578.  
  1579.  
  1580.  
  1581.  
  1582.  
  1583.  
  1584.  
  1585.   ______________________________________________________________________
  1586.   #! /bin/sh
  1587.   #
  1588.   # rc.power      This file is executed by init when there is a powerfailure.
  1589.   #
  1590.   # Version:      @(#)/etc/rc.d/rc.power   1.50    1994-08-10
  1591.   #
  1592.   # Author:       Christian Holtje, <docwhat@uiuc.edu>
  1593.   #
  1594.  
  1595.     # Set the path.
  1596.     PATH=/sbin:/etc:/bin:/usr/bin:/sbin/dangerous
  1597.  
  1598.     # Find out how we were called.
  1599.     case "$1" in
  1600.           start)
  1601.                   echo "Warning there is Power problems."  | wall
  1602.                   # Save current Run Level
  1603.                   ps | gawk '{ if (($5 == "init") && ($1 == "1")) print $6 }' \
  1604.                            | cut -f2 -d[ | cut -f1 -d] \
  1605.                            > /tmp/run.level.power
  1606.                   /sbin/shutdown -h +1m
  1607.                   ;;
  1608.           stop)
  1609.                   echo "Power is back up.  Attempting to halt shutdown." | wall
  1610.                   shutdown -c
  1611.                   ;;
  1612.           *)
  1613.                   echo "Usage:  $0 [start|stop]"
  1614.                   exit 1
  1615.                   ;;
  1616.     esac
  1617.   ______________________________________________________________________
  1618.  
  1619.  
  1620.  
  1621.  
  1622.  
  1623.   Pretty nifty, no?  Actually, there is a problem here...I haven't had
  1624.   time to figure it out...If there is a 'sh' wizard out there....
  1625.  
  1626.   There is one little detail left, that is having the UPS turn off the
  1627.   power if it was halted with the power out.  This is accomplished by
  1628.   adding this line into the end of your halt script:
  1629.  
  1630.  
  1631.  
  1632.          /sbin/backupsd /dev/backups killpower
  1633.  
  1634.  
  1635.  
  1636.  
  1637.   This will only kill the power if there is no power being supplied to
  1638.   your UPS.
  1639.  
  1640.  
  1641.   *** Testing the stuff ***
  1642.  
  1643.   This is just a short section saying this:
  1644.  
  1645.   BE CAREFUL!
  1646.  
  1647.   I recommend backing up your linux partitions, syncing several times
  1648.   before testing and just being careful in general.  Of course, I'm just
  1649.   recommending this.  I wasn't careful at all, and had to clean my
  1650.   partition several times testing my config.  But it works.  :)
  1651.   *** Where to Get It ***
  1652.  
  1653.   Miquel van Smoorenburg's SysVInit can be gotten at:
  1654.  
  1655.   sunsite.unc.edu:/pub/Linux/system/Daemons/SysVinit-2.50.tgz
  1656.  
  1657.   and a fix for some bash shells is right next-door as:
  1658.  
  1659.   sunsite.unc.edu:/pub/Linux/system/Daemons/SysVinit-2.50.patch1
  1660.  
  1661.   As to getting this HOWTO, you can email me.  docwhat@uiuc.edu  with
  1662.   the subject saying 'request' and the keyword 'backups' in body of the
  1663.   letter.  (I may automate this, and other stuff)
  1664.  
  1665.   *** Credit Where Credit's Due Dept. ***
  1666.  
  1667.   Thanks to Miquel van Smoorenburg <miquels@drinkel.nl.mugnet.org> for
  1668.   his wonderful SysVInit package and his powerd.c which helped me very
  1669.   much.
  1670.  
  1671.   Christian Holtje <docwhat@uiuc.edu> Documentation backupsd.c (what
  1672.   wasn't Miquel's) rc.power
  1673.  
  1674.   Ben Galliart <bgallia@orion.it.luc.edu> The cable Information for the
  1675.   RS-232 standard Lousy Jokes (none quoted here)
  1676.  
  1677.  
  1678.  
  1679.  
  1680.  
  1681.  
  1682.  
  1683.  
  1684.  
  1685.  
  1686.  
  1687.  
  1688.  
  1689.  
  1690.  
  1691.  
  1692.  
  1693.  
  1694.  
  1695.  
  1696.  
  1697.  
  1698.  
  1699.  
  1700.  
  1701.  
  1702.  
  1703.  
  1704.  
  1705.  
  1706.  
  1707.  
  1708.  
  1709.  
  1710.  
  1711.  
  1712.  
  1713.  
  1714.  
  1715.  
  1716.  
  1717.   ______________________________________________________________________
  1718.   /*  backupsd.c -- Simple Daemon to catch power failure signals from a
  1719.    *                Back-UPS (from APC).
  1720.    *
  1721.    *  Parts of the code are from Miquel van Smoorenburg's powerd.c
  1722.    *  Other parts are original from Christian Holtje <docwhat@uiuc.edu>
  1723.    *  I believe that it is okay to say that this is Public Domain, just
  1724.    *  give credit, where credit is due.
  1725.    *
  1726.    *  Disclaimer:  We make NO claims to this software, and take no
  1727.    *               resposibility for it's use/misuse.
  1728.    */
  1729.  
  1730.   #include <sys/types.h>
  1731.   #include <sys/ioctl.h>
  1732.   #include <fcntl.h>
  1733.   #include <errno.h>
  1734.   #include <stdlib.h>
  1735.   #include <unistd.h>
  1736.   #include <stdio.h>
  1737.   #include <signal.h>
  1738.  
  1739.   /* This is the file needed by SysVInit */
  1740.   #define PWRSTAT         "/etc/powerstatus"
  1741.  
  1742.   void powerfail(int fail);
  1743.  
  1744.   /* Main program. */
  1745.   int main(int argc, char **argv)
  1746.   {
  1747.     int fd;
  1748.     int killpwr_bit = TIOCM_RTS;
  1749.     int flags;
  1750.     int status, oldstat = -1;
  1751.     int count = 0;
  1752.  
  1753.     if (argc < 2) {
  1754.           fprintf(stderr, "Usage: %s <device> [killpower]\n", argv[0]);
  1755.           exit(1);
  1756.     }
  1757.  
  1758.     /* Open the the device */
  1759.     if ((fd = open(argv[1], O_RDWR | O_NDELAY)) < 0) {
  1760.           fprintf(stderr, "%s: %s: %s\n", argv[0], argv[1], sys_errlist[errno]);
  1761.           exit(1);
  1762.     }
  1763.  
  1764.     if ( argc >= 3  && (strcmp(argv[2], "killpower")==0) )
  1765.         {
  1766.             /* Let's kill the power! */
  1767.             fprintf(stderr, "%s: Attempting to kill the power!\n",argv[0] );
  1768.             ioctl(fd, TIOCMBIS, &killpwr_bit);
  1769.             /* Hmmm..... If you have a power outtage, you won't make it! */
  1770.             exit(0);
  1771.         }
  1772.     else
  1773.         /* Since we don't want to kill the power, clear the RTS. (killpwr_bit) */
  1774.         ioctl(fd, TIOCMBIC, &killpwr_bit);
  1775.  
  1776.   /* Become a daemon. */
  1777.     switch(fork()) {
  1778.     case 0: /* I am the child. */
  1779.                   setsid();
  1780.                   break;
  1781.     case -1: /* Failed to become daemon. */
  1782.                   fprintf(stderr, "%s: can't fork.\n", argv[0]);
  1783.                   exit(1);
  1784.     default: /* I am the parent. */
  1785.                   exit(0);
  1786.     }
  1787.  
  1788.  
  1789.     /* Now sample the DCD line. */
  1790.     while(1) {
  1791.         ioctl(fd, TIOCMGET, &flags);
  1792.         status = (flags & TIOCM_CD);
  1793.         /* Did DCD jumps to high? Then the power has failed. */
  1794.         if (oldstat == 0 && status != 0) {
  1795.             count++;
  1796.             if (count > 3) powerfail(0);
  1797.             else { sleep(1); continue; }
  1798.         }
  1799.         /* Did DCD go down again? Then the power is back. */
  1800.         if (oldstat > 0 && status == 0) {
  1801.             count++;
  1802.             if (count > 3) powerfail(1);
  1803.             else { sleep(1); continue; }
  1804.         }
  1805.         /* Reset count, remember status and sleep 2 seconds. */
  1806.         count = 0;
  1807.         oldstat = status;
  1808.         sleep(2);
  1809.     }
  1810.     /* Error! (shouldn't happen) */
  1811.     return(1);
  1812.   }
  1813.  
  1814.  
  1815.   /* Tell init the power has either gone or is back. */
  1816.   void powerfail(ok)
  1817.   int ok;
  1818.   {
  1819.     int fd;
  1820.  
  1821.     /* Create an info file needed by init to shutdown/cancel shutdown */
  1822.     unlink(PWRSTAT);
  1823.     if ((fd = open(PWRSTAT, O_CREAT|O_WRONLY, 0644)) >= 0) {
  1824.           if (ok)
  1825.                   write(fd, "OK\n", 3);
  1826.           else
  1827.                   write(fd, "FAIL\n", 5);
  1828.           close(fd);
  1829.     }
  1830.     kill(1, SIGPWR);
  1831.   }
  1832.  
  1833.   /* End of File */
  1834.   ______________________________________________________________________
  1835.  
  1836.  
  1837.  
  1838.  
  1839.  
  1840.   11.6.  APC Smart-UPS, Model 600
  1841.  
  1842.   Many people have APC Smart UPSes.  To the best of my knowledge, no one
  1843.   can run them in "smart" mode under Linux.  This is because APC refuses
  1844.   to release the protocol for the "smart" mode without a non-disclosure
  1845.   agreement.  Not very smart of them, I'd say :).
  1846.  
  1847.   The general consensus is to buy from a brand which does release the
  1848.   information.  I hear that Best is one such brand.
  1849.   If you are stuck with an APC Smart-UPS, you can still use it, but only
  1850.   in a dumb mode like all the other UPSes and as outlined above.
  1851.  
  1852.   Here's some info on how to make a cable for doing such.  You'll
  1853.   probably have to hack powerd.c as outlined in section ``Reverse-
  1854.   engineering cables and hacking powerd.c''
  1855.  
  1856.  
  1857.  
  1858.  
  1859.  
  1860.  
  1861.  
  1862.  
  1863.  
  1864.  
  1865.  
  1866.  
  1867.  
  1868.  
  1869.  
  1870.  
  1871.  
  1872.  
  1873.  
  1874.  
  1875.  
  1876.  
  1877.  
  1878.  
  1879.  
  1880.  
  1881.  
  1882.  
  1883.  
  1884.  
  1885.  
  1886.  
  1887.  
  1888.  
  1889.  
  1890.  
  1891.  
  1892.  
  1893.  
  1894.  
  1895.  
  1896.  
  1897.  
  1898.  
  1899.  
  1900.  
  1901.  
  1902.  
  1903.  
  1904.  
  1905.  
  1906.  
  1907.  
  1908.  
  1909.  
  1910.  
  1911.  
  1912.  
  1913.  
  1914.  
  1915.   From dangit@netcom.com Mon Aug 22 10:16:23 1994
  1916.   Newsgroups: comp.os.linux.misc
  1917.   Subject: UPS Monitoring Cable For APC
  1918.   From: dangit@netcom.com (Lam Dang)
  1919.   Date: Fri, 19 Aug 1994 11:56:28 GMT
  1920.   Organization: NETCOM On-line Communication Services (408 261-4700 guest)
  1921.   X-Newsreader: TIN [version 1.2 PL1]
  1922.  
  1923.   [Didn't make it the first time.]
  1924.  
  1925.   A few netters have asked about UPS monitoring cables.  This is what I
  1926.   found when I made one for my APC Smart-UPS, Model 600.  A disclaimer is in
  1927.   order.  This is just an experimenter's report; use it at your own risks.
  1928.   Please read the User's Manual first, especially Section 6.4, Computer
  1929.   Interface Port.
  1930.  
  1931.   The cable is to run between a 9-pin female connector on the UPS and a
  1932.   25-pin male connector on the PC.  Since I cut off one end of a 9-pin
  1933.   cable and replaced it with a 25-pin connector, I had to be VERY
  1934.   CAREFUL ABOUT PIN NUMBERS.  The 25-pin hood is big enough to contain a
  1935.   voltage regulator and two resistors.  I got all the materials (listed
  1936.   below) from Radio Shack for less than 10 bucks.  As required by Windows NT
  1937.   Advanced Server 3.5 (Beta 2), the "interface" between the UPS connector
  1938.   and the PC connector is as follows:
  1939.  
  1940.           UPS (9-pin)              PC (25-pin)
  1941.  
  1942.           1 (Shutdown)             20 (DTR)
  1943.           3 (Line Fail)             5 (CTS)
  1944.           4 (Common)                7 (GND)
  1945.           5 (Low Battery)           8 (DCD)
  1946.           9 (Chassis Ground)        1 (Chassis Ground)
  1947.  
  1948.   This is pretty straightforward.  You can use UPS pin 6 instead of 3
  1949.   (they're the inverse of each other).  The complication is in pulling up
  1950.   UPS open collector pins 3 (or 6) and 5.
  1951.  
  1952.   This APC model provides an unregulated output of 24 Vdc at UPS pin 8. The
  1953.   output voltage is available all the time (at least until some time after
  1954.   Low Battery has been signalled).  The supply is limited to 40 mA.  To
  1955.   pull up, UPS pin 8 is input to a +5 Vdc voltage regulator.  The output of
  1956.   the regulator goes into two 4.7K resistors.  The other end of one
  1957.   resistor connects both UPS pin 3 (Line Fail) and PC pin 5 (CTS).  That
  1958.   of the other resistor connects both UPS pin 5 (Low Battery) and PC pin 8
  1959.   (DCD).  The two resistors draw about 2 mA when closed.
  1960.  
  1961.   Test your cable without connecting it to the PC.  When the UPS is on
  1962.   line, pins 5 (CTS) and 8 (DCD) at the PC end of the cable should be very
  1963.   close to 5 Vdc, and applying a high to pin 20 (DTR) for 5 seconds should
  1964.   have no effect.  Now pull the power plug to put the UPS on battery.  Pin
  1965.   5 (CTS) should go down to zero Vdc, pin 8 (DCD) should stay the same at 5
  1966.   Vdc, and applying a high to pin 20 (DTR), e.g., by shorting pins 8 and 20,
  1967.   should shut down the UPS after about 15 seconds.
  1968.  
  1969.   Keep the UPS on battery until Low Battery is lighted on its front panel.
  1970.   Now pin 8 (DCD) should go down to zero Vdc too.  Wait until the UPS
  1971.   battery is recharged.  Then connect your cable to the PC, disable the UPS
  1972.   option switches by turning all of them ON, and run your favorite UPS
  1973.   monitoring software.
  1974.  
  1975.   For those who want to run it with Windows NT Advanced Server, the UPS
  1976.   interface voltages are NEGATIVE for both power failure (using UPS pin 3)
  1977.   and low battery conditions, and POSITIVE for remote shutdown.  Serial
  1978.   line parameters such as baud rate don't matter.
  1979.  
  1980.   I haven't tested my cable with Linux powerd.  When you do, please let us
  1981.   know.  I run NT as often as Linux on the same PC.  I must conform to NT's
  1982.   UPS scheme.  Perhaps somebody can modify powerd to work with it and post
  1983.   the source code here.
  1984.  
  1985.   List of materials:
  1986.  
  1987.           1 shielded D-sub connector hood (Radio Shack 276-1510)
  1988.           1 25-pin female D-sub crimp-type connector (276-1430)
  1989.           1 7805 +5Vdc voltage regulator (276-1770)
  1990.           2 4.7K resistors
  1991.           1 component perfboard (276-148)
  1992.           1 cable with at least one 9-pin male connector.
  1993.  
  1994.   You'll need a multimeter, a soldering iron, and a couple of hours.
  1995.  
  1996.   Hope this helps.
  1997.  
  1998.   Regards,
  1999.  
  2000.   --
  2001.   Lam Dang
  2002.   dangit@netcom.com
  2003.  
  2004.  
  2005.  
  2006.  
  2007.  
  2008.  
  2009.   12.  How to shutdown other machines on the same UPS
  2010.  
  2011.   Some people (myself included) have several Linux PCs connected to one
  2012.   UPS.  One PC monitors the UPS and needs to get the other PCs to shut
  2013.   down when the power goes out.  There are a number of ways to do this,
  2014.   all are do-it-yourself currently, and most are just hypothetical.
  2015.  
  2016.   We assume the PCs can communicate over a network.  Call the PC that
  2017.   monitors the UPS the master & the other PCs the slaves.
  2018.  
  2019.  
  2020.  
  2021.   12.1.  UPS status port method
  2022.  
  2023.   Set up a port on the master which, when connected to, either sends
  2024.   "OK", "FAIL", or "BATLOW", the first when the power is ok, the second
  2025.   when the power has failed, and the third when the battery is low.
  2026.   Model this on port 13 (the time port) which one can telnet to &
  2027.   receive the local time.
  2028.  
  2029.   Have the slaves run versions of powerd that look at this port instead
  2030.   of checking a serial line.
  2031.  
  2032.   I think this is probably the best method, and intend to eventually
  2033.   upgrade my systems to use it.
  2034.  
  2035.  
  2036.   12.2.  Broadcast method
  2037.  
  2038.   Same as section ``UPS status port method'' except send an ethernet
  2039.   broadcast message that the power has just gone down.
  2040.  
  2041.   This might have security implications, since it could be spoofed.
  2042.  
  2043.  
  2044.  
  2045.  
  2046.  
  2047.   12.3.  Dummy login method
  2048.  
  2049.   Set up dummy logins on the slaves with login names powerok and
  2050.   powerfail, both with the same UID.  Make /etc/powerokscript the shell
  2051.   of the powerok user, and make /etc/powerfailscript the shell of the
  2052.   powerfail user.  On the master, have the /etc/powerokscript rlogin to
  2053.   each slave as user powerok and have the /etc/powerfailscript rlogin to
  2054.   each slave as user powerfail.  Put a .rhosts file on each slave in the
  2055.   home directory of powerok and powerfail to allow root from the master
  2056.   to login as user powerok and powerfail to each slave.
  2057.  
  2058.   This is the system I'm currently using.  Unfortunately, there are some
  2059.   difficulties in getting the remote logins to execute and return
  2060.   without hanging.  One probably wants the /etc/powerfailscript on the
  2061.   master to rsh to the slaves in background so that the
  2062.   /etc/powerfailscript doesn't hang.  However, I never managed to get
  2063.   logging in in background to work right.  I even tried arcane
  2064.   combinations such as having /etc/powerfailscript run foo in background
  2065.   and having foo log into the slave.  Whatever I did gave problems with
  2066.   the thing being stopped for tty input (or output, I can't remember).
  2067.  
  2068.   Also, this might create security holes.
  2069.